package com.ase.singleton.single;

/**
 * @author gyhstart
 * @create 2021/3/6 - 10:35
 * 单例模式 volatile
 **/
public class Singleton2 {
    private volatile static Singleton2 singleton2 = null;
    
    private Singleton2(){
        System.out.println("singleton2 = " + singleton2);
    }
    
    public static Singleton2 getInstance(){
        if (singleton2 == null){
            synchronized (Singleton2.class){
                if (singleton2 == null){
                    singleton2 = new Singleton2();
                }
            }
        }
        return singleton2;
    }
}
